package com.lbc.controller;

import com.lbc.bean.entity.User;
import com.lbc.common.constants.Constants;
import com.lbc.common.resp.ResponseResult;
import com.lbc.common.utils.JwtUtils;
import com.lbc.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xyl
 * @date 2021-03-15 19:35
 */
@Api(tags = "用户接口")
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("获取个人信息")
    @GetMapping("/myInfo")
    public ResponseResult getMyInfo(){
        User user = userService.getUserById(JwtUtils.getUserId());
        if(Constants.ROLE_SCHOOL == user.getRoleId()){
            return ResponseResult.success(userService.getMySchoolInfo(user.getUserId()));
        }else if(Constants.ROLE_ORGANIZATION == user.getRoleId()){
            return ResponseResult.success(userService.getMyOrganizationInfo(user.getUserId()));
        }else{
            return ResponseResult.success(userService.getUserVOById(JwtUtils.getUserId()));
        }
    }
}
